﻿using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class JG_DutiesPlanAssessedPersonService : BaseAppService<JG_DutiesPlanAssessedPersonDto, JG_DutiesPlanAssessedPerson, JG_DutiesPlanAssessedPersonRepository>
    {
        readonly ExcelHelp _excelHelp;
        public JG_DutiesPlanAssessedPersonService(JG_DutiesPlanAssessedPersonRepository repository, ExcelHelp excelHelp) : base(repository)
        {
            _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<JG_DutiesPlanAssessedPerson, JG_DutiesPlanAssessedPersonDto>
            GetLoadPageOffsetMode(PagingModel<JG_DutiesPlanAssessedPersonDto>
                pagingQueryModel)
        {
            var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
            var baseQuery = _repository.QueryBase().AsNoTracking();
            loadPageOffsetModel.QueryWhere = this.CreateQRList()

     .Add("DutiesPlanID", "=") //
     .Add("DeptID", "=") //
     .Add("PostID", "=") //
     .Add("UserID", "=") //
     .Add("AssessmentUserID", "=") //
     .Add("Remark", "=") //
     .Add("SelfEvaluationScore", "=") //
     .Add("OtherEvaluationScore", "=") //
     .Add("TotalScore", "=") //
     .Add("zwpj", "=") //
     .Add("xybtsjh", "=") //
     .Add("ztpj", "=") //
     .Add("ys", "=") //
     .Add("dgjx", "=") //
     .Add("SelfEvaluationDate", "=") //
     .Add("OtherEvaluationDate", "=") //
     .Add("IsComplete", "=");//


            loadPageOffsetModel.BasqQuery = baseQuery;
            loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
            loadPageOffsetModel.Selector = model => new JG_DutiesPlanAssessedPerson()
            {
                Id = model.Id,
                DutiesPlanID = model.DutiesPlanID,//
                DeptID = model.DeptID,//
                PostID = model.PostID,//
                UserID = model.UserID,//
                AssessmentUserID = model.AssessmentUserID,//
                Remark = model.Remark,//
                SelfEvaluationScore = model.SelfEvaluationScore,//
                OtherEvaluationScore = model.OtherEvaluationScore,//
                TotalScore = model.TotalScore,//
                zwpj = model.zwpj,//
                xybtsjh = model.xybtsjh,//
                ztpj = model.ztpj,//
                ys = model.ys,//
                dgjx = model.dgjx,//
                SelfEvaluationDate = model.SelfEvaluationDate,//
                OtherEvaluationDate = model.OtherEvaluationDate,//
                IsComplete = model.IsComplete,//
            };
            return loadPageOffsetModel;
        }


        public async Task<IPageModel<JG_DutiesPlanAssessedPersonDto>> GetList(PagingModel<JG_DutiesPlanAssessedPersonDto>
            pagingQueryModel)
        {
            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
            return await base.LoadPageOffsetAsync(loadPageOffsetModel);
        }


        public async Task<string>
            Export(PagingModel<JG_DutiesPlanAssessedPersonDto>
                pagingQueryModel)
        {
            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
            var excelData = DataList.Select(model => new
            {
                model.DutiesPlanID,
                DutiesPlanID_title = "",
                model.DeptID,
                DeptID_title = "",
                model.PostID,
                PostID_title = "",
                model.UserID,
                UserID_title = "",
                model.AssessmentUserID,
                AssessmentUserID_title = "",
                model.Remark,
                Remark_title = "",
                model.SelfEvaluationScore,
                SelfEvaluationScore_title = "",
                model.OtherEvaluationScore,
                OtherEvaluationScore_title = "",
                model.TotalScore,
                TotalScore_title = "",
                model.zwpj,
                zwpj_title = "",
                model.xybtsjh,
                xybtsjh_title = "",
                model.ztpj,
                ztpj_title = "",
                model.ys,
                ys_title = "",
                model.dgjx,
                dgjx_title = "",
                model.SelfEvaluationDate,
                SelfEvaluationDate_title = "",
                model.OtherEvaluationDate,
                OtherEvaluationDate_title = "",
                model.IsComplete,
                IsComplete_title = "",
            }).ToList();




            return _excelHelp.Create(excelData);
        }

    }

}
